package djboom.materials.display.page.work2 {
	import djboom.materials.Work;
	import djboom.materials.core.BitmapDataCore;
	import djboom.materials.core.DataCore;
	import djboom.materials.display.devices.BeamScales;
	import djboom.materials.display.devices.GasBurner;
	import djboom.materials.display.elements.Instruction;
	import djboom.materials.display.elements.SampleMaterial;
	import djboom.materials.display.elements.TableData;
	import djboom.materials.display.elements.TableDataCell;
	import djboom.materials.display.elements.Window;
	import djboom.materials.display.page.Navigation;
	import djboom.materials.display.page.Page;
	import djboom.materials.events.BeamScalesEvent;
	import djboom.materials.events.InstructionEvent;
	import djboom.materials.events.PageEvent;
	import djboom.materials.events.TableDataCellEvent;
	import djboom.materials.events.WindowEvent;

	import com.greensock.TweenLite;
	import com.greensock.easing.Cubic;
	import com.greensock.easing.Quad;
	import com.greensock.easing.Quart;

	import org.casalib.display.CasaBitmap;
	import org.casalib.display.CasaShape;
	import org.casalib.display.CasaTextField;
	import org.casalib.util.StageReference;

	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.AntiAliasType;
	import flash.text.TextFieldAutoSize;

	/**
	 * .
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 28.04.2010
	 * 
	 */

	public class Page4 extends Page {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------

		public static const MATERIAL_PHASE_SCALE:String = "materialPhaseScale";		public static const MATERIAL_PHASE_TABLE:String = "materialPhaseTable";		public static const MATERIAL_PHASE_WAX:String = "materialPhaseWax";
		public static const MATERIAL_PHASE_GLASS:String = "materialPhaseGlass";

		/**
		 * Штатив.
		 * 
		 */

		private static const TRIPOD:String = "work2.Tripod";

		
		/**
		 * Штатив.
		 * 
		 */

		private static const BENCH:String = "work2.Bench";

		
		/**
		 * Штатив.
		 * 
		 */

		private static const GLASS:String = "work2.Glass";

		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------

		private var _materialsList:XMLList;

		private var _sampleMaterialXML:XML;

		private var _tableDataXML:XML;

		private var _heightFall:Number;

		private var _sampleMaterialPhase:String;
		private var _materialWeight:String;
		private var _materialMaterialWax:String;

		private var _instruction:Instruction;
		private var _sampleMaterial:SampleMaterial;
		private var _tableData:TableData;
		private var _window:Window;
		private var _beamScales:BeamScales;
		private var _materialHotSpot:CasaShape;
		private var _helpField:CasaTextField;
		private var _gasBurner:GasBurner;
		private var _tripod:CasaBitmap;
		private var _bench:CasaBitmap;
		private var _glass:CasaBitmap;
		private var _materialMaterialWaxWater:String;
		private var _hintBitmap:CasaBitmap;

		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function Page4() {
			super();
		}	 

		// ----------------------------------------------------------------------------
		// Методы класса.
		// ----------------------------------------------------------------------------

		override public function init():void {
			// Создаем заголовок страницы.
			createTitleWork("Определение средней плотности на образцах неправильной геометрической формы", 2);
            
			// Создаем инструкцию.
			_instruction = new Instruction(DataCore.INSTRUCTION_WORK_2.child("instruction"));
			_instruction.addEventListener(InstructionEvent.LIGHT_CELL, lightTableCell);
			_instruction.addEventListener(InstructionEvent.AUTO, applyAuto);
			addChild(_instruction);
            
			_materialsList = DataCore._materialsWork2XML.child("material").(@select == "true");
            
			createTableDataXML();
            
			_tableData = new TableData(BitmapDataCore.getBitmapData(BitmapDataCore.WORK2_TABLEDATA), _tableDataXML, new Point(16, 108), TableDataCell.CELL_FORMAT_19PX);
			_tableData.x = 20;
			_tableData.y = 82 + _instruction.scrollHeight;
			_tableData.addEventListener(TableDataCellEvent.INPUT_ERROR, inputError);
			_tableData.addEventListener(TableDataCellEvent.INPUT_SUCCESS, inputSuccess);
			_tableData.addEventListener(TableDataCellEvent.INPUT_LAST_CELL, inputLastCell);
            
            
			_tableData.scrollRect = new Rectangle(0, _tableData.height, _tableData.width, 0);
			addChild(_tableData);
            
			_beamScales = new BeamScales();
			_beamScales.x = 530;
			_beamScales.y = 298;
			_beamScales.addEventListener(InstructionEvent.REFRESH, refreshInstruction);
			_beamScales.addEventListener(BeamScalesEvent.ENABLE_SAMPLE, enableSample);
			_beamScales.addEventListener(BeamScalesEvent.REMOVE_WEIGHTS, removeWeights);
			_beamScales.addEventListener(BeamScalesEvent.DESTROY, destroyWeights);
			_beamScales.enable(MATERIAL_PHASE_SCALE);
			addChild(_beamScales);
            
            
			_sampleMaterialXML = _materialsList[0] as XML;
            
			_sampleMaterial = new SampleMaterial(BitmapDataCore.getBitmapData(_sampleMaterialXML.attribute("sampleBitmapData").toString()));
			_sampleMaterial.x = 100;
			_sampleMaterial.y = Work.HEIGHT - 52 - _sampleMaterial.height;
			_sampleMaterial.tabEnabled = false;
			_sampleMaterial.addEventListener(InstructionEvent.REFRESH, refreshInstruction);
			addChild(_sampleMaterial);
            
			_materialHotSpot = new CasaShape();
			_materialHotSpot.graphics.beginFill(0, 0);
			_materialHotSpot.graphics.drawRect(0, 0, 20, 150);
			_materialHotSpot.graphics.endFill();
			_materialHotSpot.x = 595;
			_materialHotSpot.y = 510;
			_materialHotSpot.visible = false;
		}

		private function createTableDataXML():void {
			_tableDataXML = <tabledata></tabledata>;
            
			for each (var materialXML:XML in _materialsList) {
				var materialName:String = materialXML.attribute("name").toString();				var materialWeight:String = materialXML.attribute("weight").toString();				var materialMaterialWax:String = materialXML.attribute("materialwax").toString();				var materialWaxWeight:String = materialXML.attribute("waxweight").toString();				var materialWaxAmount:String = materialXML.attribute("waxamount").toString();				var materialMaterialWaxWater:String = materialXML.attribute("materialwaxwater").toString();				var materialMaterialAmount:String = materialXML.attribute("materialamount").toString();				var materialMaterialAverage_G:String = materialXML.attribute("materialaverage_g").toString();				var materialMaterialAverage_KG:String = materialXML.attribute("averageHardness_KG").toString();
				
				_materialWeight = materialWeight;				_materialMaterialWax = materialMaterialWax;
				_materialMaterialWaxWater = materialMaterialWaxWater;
                
				_tableDataXML.appendChild(<row>
                    <cell align="left" width="139">
                      <data>{materialName}</data>
                    </cell>
                    <cell align="center" width="89">
                      <data> </data>
                      <checkData>{materialWeight}</checkData>
                    </cell>
                    <cell align="center" width="141">
                      <data> </data>
                      <checkData>{materialMaterialWax}</checkData>
                    </cell>
                    <cell align="center" width="97">
                      <data> </data>
                      <checkData>{materialWaxWeight}</checkData>
                    </cell>
                    <cell align="center" width="103">
                      <data> </data>
                      <checkData>{materialWaxAmount}</checkData>
                    </cell>
                    <cell align="center" width="142">
                      <data> </data>
                      <checkData>{materialMaterialWaxWater}</checkData>
                    </cell>
                    <cell align="center" width="92">
                      <data> </data>
                      <checkData>{materialMaterialAmount}</checkData>
                    </cell>
                    <cell align="center" width="66">
                      <data> </data>
                      <checkData>{materialMaterialAverage_G}</checkData>
                    </cell>
                    <cell align="center" width="70">
                      <data> </data>
                      <checkData>{materialMaterialAverage_KG}</checkData>
                    </cell>
                </row>);
			}
		}

		
		
		private function lightTableCell(event:InstructionEvent):void {
			_tableData.y = 82 + _instruction.scrollHeight;
			_tableData.enableCell(0 + event.cellName);
			
			TweenLite.to(_tableData, 0.5, {scrollRect: {x: 0, y: 0, width: _tableData.width, height: _tableData.scrollHeight}, ease: Cubic.easeInOut, delay: 1});
			
			switch(_instruction.instructionID) {
				case 3:
					_helpField = new CasaTextField();
					_helpField.embedFonts = true;
					_helpField.selectable = false;
					_helpField.defaultTextFormat = TableDataCell.CELL_FORMAT_19PX;
					_helpField.autoSize = TextFieldAutoSize.LEFT;
					_helpField.antiAliasType = AntiAliasType.ADVANCED;
					_helpField.mouseEnabled = false;
					_helpField.thickness = 50;
					_helpField.x = 38;
					_helpField.y = 295;
					_helpField.text = "Масса гирь, уравновешивающих образец, равна " + _materialWeight + " г";
					addChild(_helpField);
					
					TweenLite.from(_helpField, 1, {alpha: 0, delay: 0.5});
					
					break;
					
				case 13:
					_helpField = new CasaTextField();
					_helpField.embedFonts = true;
					_helpField.selectable = false;
					_helpField.defaultTextFormat = TableDataCell.CELL_FORMAT_19PX;
					_helpField.autoSize = TextFieldAutoSize.LEFT;
					_helpField.antiAliasType = AntiAliasType.ADVANCED;
					_helpField.mouseEnabled = false;
					_helpField.thickness = 50;
					_helpField.x = 38;
					_helpField.y = 295;
					_helpField.text = "Масса гирь, уравновешивающих образец, равна " + _materialMaterialWax + " г";
					addChild(_helpField);
                    
					TweenLite.from(_helpField, 1, {alpha: 0, delay: 0.5});
                    
					break;
					
				case 21:
					_helpField = new CasaTextField();
					_helpField.embedFonts = true;
					_helpField.selectable = false;
					_helpField.defaultTextFormat = TableDataCell.CELL_FORMAT_19PX;
					_helpField.autoSize = TextFieldAutoSize.LEFT;
					_helpField.antiAliasType = AntiAliasType.ADVANCED;
					_helpField.mouseEnabled = false;
					_helpField.thickness = 50;
					_helpField.x = 38;
					_helpField.y = 295;
					_helpField.text = "Вес парафинированного образца в воде равен " + _materialMaterialWaxWater + " г";
					addChild(_helpField);
                    
					TweenLite.from(_helpField, 1, {alpha: 0, delay: 0.5});
                    
					break;
					
				case 23:
					
					
					_hintBitmap = new CasaBitmap(BitmapDataCore.getBitmapData(BitmapDataCore.WORK2_HINT_1));
					_hintBitmap.x = 38;
					_hintBitmap.y = 295;
					addChild(_hintBitmap);
					
                    
					TweenLite.from(_hintBitmap, 1, {alpha: 0, delay: 0.5});
                    
					break;
			}
		}

		private function inputError(event:TableDataCellEvent):void {
			lockPage();
            
			_window = new Window();
			_window.addEventListener(WindowEvent.CLOSE, repeatEnableCell);
			_window.init("Внимание!", "Введены некорректные данные");
			addChild(_window);
		}

		private function repeatEnableCell(event:WindowEvent):void {
			unlockPage();
            
			if (_window != null) {
				_window.destroy();
				_window = null;
			}
            
			_tableData.repeatEnableCell();
		}

		private function inputSuccess(event:TableDataCellEvent):void {
			var inputCell:Boolean = _instruction.checkInputCell();
			
			if (!inputCell) TweenLite.to(_tableData, 0.5, {scrollRect: {x: 0, y: _tableData.scrollHeight, width: _tableData.width, height: 0}, ease: Cubic.easeInOut});
            
			_instruction.nextInstruction();
			
			switch(_instruction.instructionID) {
				case 5:
					_helpField.destroy();
					_helpField = null;
                    
					_beamScales.disable();
					break;
				case 15:
					_helpField.destroy();
					_helpField = null;
                    
					_beamScales.disable();
					break;
				case 23:
					_helpField.destroy();
					_helpField = null;
                    
					_beamScales.remove();
					break;
					
				case 25:
					_hintBitmap.destroy();
					_hintBitmap = null;
                    
					break;
			}
		}

		private function inputLastCell(event:TableDataCellEvent):void {
			lockPage();
            
			_window = new Window();
            
			Navigation.toggleEnabled(Page.WORK_2_PAGE_1, false);
			
			var enableWork1:String = XML(XMLList(Navigation.NAVIGATION_XML.child("item").(@page == Page.WORK_1_PAGE_1))[0]).attribute("enable").toString();
			
			if (enableWork1 == "false") {
				Navigation.toggleEnabled(Page.WORK_3_PAGE_1, true);
			}
            
			_window.addEventListener(WindowEvent.CLOSE, navigationPage);
			_window.init("Поздравляем!", "Вы успешно справились с работой №2, можете приступить к следующей.");
			addChild(_window);
		}

		private function navigationPage(event:WindowEvent):void {
			var pageEvent:PageEvent = new PageEvent(PageEvent.CHANGE);
			pageEvent.pageName = Page.NAVIGATION;            
			dispatchEvent(pageEvent);
		}

		
		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------

		
		
		private function destroyWeights(event:BeamScalesEvent):void {
			TweenLite.to(_beamScales, 1, {alpha: 0, delay: 0.5, onComplete: removeScale});
			
			TweenLite.to(_sampleMaterial, 1, {alpha: 0, delay: 0.5});
			TweenLite.to(_bench, 1, {alpha: 0, delay: 0.5});
			TweenLite.to(_glass, 1, {alpha: 0, delay: 0.5});
		}

		private function removeScale():void {
			_beamScales.destroy();
			_beamScales = null;
			
			if (_sampleMaterial != null) {
				_sampleMaterial.destroy();
				_sampleMaterial = null;
			}
			
			if (_bench != null) {
				_bench.destroy();
				_bench = null;
			}
			
			if (_glass != null) {
				_glass.destroy();
				_glass = null;
			}
			
			_instruction.nextInstruction();
		}

		private function enableSample(event:BeamScalesEvent):void {
			_sampleMaterialPhase = event.sampleMaterialPhase;
			
			switch(_sampleMaterialPhase) {
				case MATERIAL_PHASE_SCALE:
				
					_materialHotSpot.visible = true;
					addChild(_materialHotSpot);
				
					break;
				case MATERIAL_PHASE_WAX:
                
					_materialHotSpot.visible = true;
					addChild(_materialHotSpot);
                
					break;
				case MATERIAL_PHASE_GLASS:
					
					_beamScales.balanceMaterial(_sampleMaterial, 0.5);

					break;
			}
			
			_sampleMaterial.addEventListener(MouseEvent.MOUSE_DOWN, setupDragSample);
		}

		private function setupDragSample(event:MouseEvent):void {
			_sampleMaterial.removeEventListener(MouseEvent.MOUSE_DOWN, setupDragSample);
			 
			dragSprite();
		}

		/**
		 * Таскаем объект.
		 * 
		 */

		private function dragSprite(event:MouseEvent = null):void {
			_heightFall = Work.HEIGHT - _sampleMaterial.height - 52;
			
			         
			switch(_sampleMaterialPhase) {
				case MATERIAL_PHASE_SCALE:
                    
					_sampleMaterial.startDrag(false, new Rectangle(3, 82 + _instruction.height, Work.WIDTH - 6 - _sampleMaterial.width, Work.HEIGHT - 82 - _instruction.height - 52 - _sampleMaterial.height));
                    
					break;
                    
                    
				case MATERIAL_PHASE_WAX:
					
					
					_sampleMaterial.hideRope();
					
					_sampleMaterial.startDrag(false, new Rectangle(3, 82 + _instruction.height, Work.WIDTH - 6 - _sampleMaterial.width, Work.HEIGHT - 82 - _instruction.height - 52 - _sampleMaterial.height));
					
					break;
			}
            
			_sampleMaterial.addEventListener(MouseEvent.MOUSE_UP, stopDragSprite);
			StageReference.getStage().addEventListener(MouseEvent.MOUSE_UP, stopDragSprite);
		}

		/**
		 * Останавливаем таскание объекта.
		 * 
		 */

		private function stopDragSprite(event:MouseEvent = null):void {
			_sampleMaterial.stopDrag();
            
			StageReference.getStage().removeEventListener(MouseEvent.MOUSE_UP, stopDragSprite);
			_sampleMaterial.removeEventListener(MouseEvent.MOUSE_UP, stopDragSprite);
			
			var time:Number;
			
			switch(_sampleMaterialPhase) {
				case MATERIAL_PHASE_SCALE:
					
					if (_materialHotSpot.hitTestObject(_sampleMaterial)) {

						_sampleMaterial.blocked = true;
						
						_materialHotSpot.visible = false;
						removeChild(_materialHotSpot);
                        						
						time = 0.2;
						TweenLite.to(_sampleMaterial, time, {y:  Work.HEIGHT - 52 - _sampleMaterial.height - 59, ease: Quad.easeIn, onComplete: scaleFeelWeight});
					} else {
						time = ((Work.HEIGHT - 52 - _sampleMaterial.height) - _sampleMaterial.y) / 1000;
						
						
						TweenLite.to(_sampleMaterial, time, {y:  Work.HEIGHT - 52 - _sampleMaterial.height, ease: Quad.easeIn});
						
						_sampleMaterial.addEventListener(MouseEvent.MOUSE_DOWN, setupDragSample);			
					}
					
					break;
					
					
				case MATERIAL_PHASE_WAX:
                    
					if (_materialHotSpot.hitTestObject(_sampleMaterial)) {

						_sampleMaterial.blocked = true;
                        
						_materialHotSpot.visible = false;
						removeChild(_materialHotSpot);
						

						time = 0.2;
						
						TweenLite.to(_sampleMaterial, time, {y:  Work.HEIGHT - _sampleMaterial.height - 109, ease: Quad.easeIn, onComplete: scaleFeelWeight});
					} else {
						time = ((Work.HEIGHT - 52 - _sampleMaterial.height) - _sampleMaterial.y) / 1000;
                        
						_sampleMaterial.showRope();
                        

						TweenLite.to(_sampleMaterial, 0.4, {x: 102, y: 441, ease: Cubic.easeInOut});
						
                        
						_sampleMaterial.addEventListener(MouseEvent.MOUSE_DOWN, setupDragSample);           
					}
                    
					break;
			}
		}

		
		
		private function scaleFeelWeight():void {
			_instruction.nextInstruction();
			
			switch(_sampleMaterialPhase) {
				case MATERIAL_PHASE_SCALE:

					_beamScales.balanceMaterial(_sampleMaterial, 0.8);
                    
					break;
                    
                    
				case MATERIAL_PHASE_WAX:
                    
					_beamScales.balanceMaterial(_sampleMaterial, 1);
					
					TweenLite.to(_tripod, 1, {alpha: 0, onComplete: removeTripod});
                    
					break;
			}
		}

		private function removeTripod():void {
			_tripod.destroy();
			_tripod = null;
		}

		
		/**
		 * Обновляем инструкции к работе.
		 * 
		 */

		private function refreshInstruction(event:InstructionEvent):void {
			_instruction.nextInstruction();
			
			
			switch(_instruction.instructionID) {
				case 6:
					_beamScales.removeWeights();
					

					_sampleMaterial.addEventListener(MouseEvent.MOUSE_DOWN, dragMaterialOfScale);
					break;
					
				case 9:
					_sampleMaterial.waxMaterial();
					break;
					
				case 10:
					_gasBurner.disable();
					break;
					
				case 11:
					TweenLite.to(_gasBurner, 1, {alpha: 0, delay: 0.5, onComplete: removeGasBurner});
                   
					_beamScales.enable(MATERIAL_PHASE_WAX);
					
					break;
					
				case 16:
					_beamScales.removeWeights();
                    

					_sampleMaterial.addEventListener(MouseEvent.MOUSE_DOWN, dragMaterialOfScale);
					break;
			}
		}

		private function removeGasBurner():void {
			_gasBurner.destroy();
			_gasBurner = null;
		}

		
		private function dragMaterialOfScale(event:MouseEvent):void {
			_sampleMaterial.removeEventListener(MouseEvent.MOUSE_DOWN, dragMaterialOfScale);
			 
			_heightFall = Work.HEIGHT - _sampleMaterial.height - 52;
            
			_sampleMaterial.startDrag(false, new Rectangle(3, 82 + _instruction.height, Work.WIDTH - 6 - _sampleMaterial.width, Work.HEIGHT - 82 - _instruction.height - 52 - _sampleMaterial.height));
            
			_sampleMaterial.addEventListener(MouseEvent.MOUSE_UP, removeMaterialOfScale);
			StageReference.getStage().addEventListener(MouseEvent.MOUSE_UP, removeMaterialOfScale);
		}

		
		private function removeMaterialOfScale(event:MouseEvent = null):void {
			_sampleMaterial.stopDrag();
            
			StageReference.getStage().removeEventListener(MouseEvent.MOUSE_UP, removeMaterialOfScale);
			_sampleMaterial.removeEventListener(MouseEvent.MOUSE_UP, removeMaterialOfScale);
            
			var time:Number;
            
			time = ((Work.HEIGHT - 52 - _sampleMaterial.height) - _sampleMaterial.y) / 1000;
			TweenLite.to(_sampleMaterial, time, {y:  Work.HEIGHT - 52 - _sampleMaterial.height, ease: Quad.easeIn});

			_sampleMaterial.blocked = false;
			

			if (_beamScales.weightsList.size == 0) {
				_instruction.nextInstruction();
			}
		}

		private function removeWeights(event:BeamScalesEvent):void {
			if (!_sampleMaterial.blocked) {
				_instruction.nextInstruction();
			}
		}

		/**
		 * Автоматическое действие.
		 * Обвязываем образец нитью.
		 * 
		 */

		public function ropeOnMaterial():void {
			_gasBurner = new GasBurner();
			_gasBurner.x = 240;			_gasBurner.y = 548;
			_gasBurner.addEventListener(InstructionEvent.REFRESH, refreshInstruction);
			
			
			TweenLite.from(_gasBurner, 0.5, {x:  -_gasBurner.width, ease: Quart.easeOut});
			
			_tripod = new CasaBitmap(BitmapDataCore.getBitmapData(TRIPOD));
			_tripod.x = 19;			_tripod.y = 264;
			addChild(_tripod);
			
			TweenLite.from(_tripod, 0.5, {x:  -_tripod.width, delay: 0.5, ease: Quart.easeOut});
			
			TweenLite.to(_sampleMaterial, 0.5, {x: 102, y: 441, delay: 1, ease: Cubic.easeInOut, onComplete: enableGas});
			
			_sampleMaterial.createRope();
			
			addChild(_sampleMaterial);
			addChild(_gasBurner);
		}

		private function enableGas():void {
			_instruction.nextInstruction();
			
			_gasBurner.enable();
		}

		/**
		 * Показываем скамейку и стакан.
		 * 
		 */

		public function showWoodAndGlass():void {
			_beamScales.tweenWeights();
			
			_bench = new CasaBitmap(BitmapDataCore.getBitmapData(BENCH));
			_bench.x = 551;			_bench.y = 627;
			addChild(_bench);
			
			TweenLite.from(_bench, 0.5, {alpha:  0});
			
			_glass = new CasaBitmap(BitmapDataCore.getBitmapData(GLASS));
			_glass.x = 559;
			_glass.y = 473;
			addChild(_glass);
            
			TweenLite.from(_glass, 0.5, {alpha:  0});
			
			TweenLite.to(_sampleMaterial, 0.5, {x:  567, y: 561, ease: Cubic.easeInOut, onComplete: showRope});
		}

		private function showRope():void {
			_sampleMaterial.showRope();
			
			_instruction.nextInstruction();
			
			_beamScales.enable(MATERIAL_PHASE_GLASS);
		}

		
		
		
		/**
		 * Очистка страницы.
		 * 
		 */

		override protected function clearPage(event:Event):void {
			super.clearPage(event);
			
			_materialsList = null;
			
			_sampleMaterialXML = null;
			_tableDataXML = null;
			_heightFall = -1;
			
			
			if (_sampleMaterial != null) {
				_sampleMaterial.destroy();
				_sampleMaterial = null;  
			}
			
			_tableData.destroy();
			_tableData = null;
			
			_instruction.destroy();
			_instruction = null;
			
			if (_window != null) {
				_window.destroy();
				_window = null;
			}
			
			if (_beamScales != null) {
				_beamScales.destroy();
				_beamScales = null;
			}
			
			if (_materialHotSpot != null) {
				_materialHotSpot.destroy();
				_materialHotSpot = null;
			}
			
			if (_helpField != null) {
				_helpField.destroy();
				_helpField = null;
			}
			
			if (_gasBurner != null) {
				_gasBurner.destroy();
				_gasBurner = null;
			}
			
			if (_tripod != null) {
				_tripod.destroy();
				_tripod = null;
			}
			
			if (_bench != null) {
				_bench.destroy();
				_bench = null;
			}
			
			if (_glass != null) {
				_glass.destroy();
				_glass = null;
			}
		}
        
		// ----------------------------------------------------------------------------
        // Публичные свойства.
        // ----------------------------------------------------------------------------
	}
}
